import '../../interface/chat_room_leaf_interface.dart';

class ProgramListPageModel extends ChatRoomChangeNotifier {
  // ChannelProgramsData? data;

  // List<ChannelProgramItem> todayData = [];
  // List<ChannelProgramItem> tomorrowData = [];

  // ChannelProgramItem? adminCanStartItem;

  /// 标记是否有进行中的活动
  bool isProgress = false;

  /// 预约车手总数
  int? totalNumber;

  // Channel? get channel {
  //   return roomModel.channel;
  // }

  // String getProgramTimeStr(ChannelProgramItem item) {
  //   DateTime dateTime =
  //       DateTime.fromMillisecondsSinceEpoch(item.dateStamp.toInt());
  //   String result = "";
  //   result += "${dateTime.year}-${dateTime.month}-${dateTime.day} ";
  //   String weekDay = DateUtil.getWeekDay(dateTime.weekday);
  //   result += "$weekDay ";
  //   result += item.startTime;
  //   return result;
  // }

  @override
  observeMessage(int messageId, data) {}

  @override
  onRootProxyModelCreated() {
    initData();
    // mockData();
  }

  mockData() {
    // UserManager.instance.currentUser!.clubManager = false;
    // UserManager.instance.currentUser!.job = Job.GS;
    // data = ChannelProgramsData.create();
    // ChannelProgramItem notbeginItem = getmockitem();
    // adminCanStartItem = notbeginItem;
    // data!.programItem.add(notbeginItem);
    // ChannelProgramItem ingItem = getmockitem();
    // ingItem.status = ProgramStatus.PROCESS_ING;
    // data!.programItem.add(ingItem);
    // ChannelProgramItem cancelItem = getmockitem();
    // cancelItem.status = ProgramStatus.CANCELLED;
    // data!.programItem.add(cancelItem);
    // ChannelProgramItem endItem = getmockitem();
    // endItem.status = ProgramStatus.FINISHED;
    // data!.programItem.add(endItem);
    notifyListeners();
  }

  // ChannelProgramItem getmockitem() {
  //   ChannelProgramItem notbeginItem = ChannelProgramItem.create();
  //   notbeginItem.status = ProgramStatus.NOT_BEGUN;
  //   notbeginItem.desc = "测试副驾驶空间啊付了款久等啦发卡机送达了";
  //   notbeginItem.subscribeNumber = 3;
  //   notbeginItem.topic = "测试标题费";
  //   notbeginItem.startTimeSeconds =
  //       DateTime.now().millisecondsSinceEpoch ~/ 1000;
  //   return notbeginItem;
  // }

  // startProgram(ChannelProgramItem item, int rid) async {
  //   var result = await RtcApi.instance
  //       .startProgram(StartProgramReq(programId: item.programId));
  //   if (result.isSuccess) {
  //     reportActivityStart(rid, item.topic, item.subscribeNumber.toInt());
  //     initData();
  //   } else {
  //     showToast(result.errorMsg ?? T.current!.check_network_retry);
  //   }
  // }

  // endProgram(ChannelProgramItem item) async {
  //   var result = await RtcApi.instance
  //       .endProgram(EndProgramReq(programId: item.programId));
  //   if (result.isSuccess) {
  //     isProgress = false;
  //     initData();
  //   } else {
  //     showToast(result.errorMsg ?? T.current!.check_network_retry);
  //   }
  // }

  // cancelProgram(ChannelProgramItem item) async {
  //   var result = await RtcApi.instance
  //       .cancelProgram(CancelProgramReq(programId: item.programId));
  //   if (result.isSuccess) {
  //     initData();
  //   } else {
  //     showToast(result.errorMsg ?? T.current!.check_network_retry);
  //   }
  // }

  // renewProgram(ChannelProgramItem item) async {
  //   var result = await RtcApi.instance
  //       .renewProgram(RenewProgramReq(programId: item.programId));
  //   if (result.isSuccess) {
  //     initData();
  //   } else {
  //     showToast(result.errorMsg ?? T.current!.check_network_retry);
  //   }
  // }

  // subscribeProgram(ChannelProgramItem item, int rid) async {
  //   var result = await RtcApi.instance
  //       .subscribeProgram(SubscribeProgramReq(programId: item.programId));
  //   if (result.isSuccess) {
  //     reportActivityBook(rid, item.topic, item.subscribeNumber.toInt());
  //     initData();
  //   } else {
  //     showToast(result.errorMsg ?? T.current!.check_network_retry);
  //   }
  // }

  initData() async {
    // var result = await RtcApi.instance.getChannelProgramsData();
    // if (result.isSuccess) {
    //   data = result.data;
    //   DateTime now = DateTime.now();
    //   DateTime tomorrow = DateTime.fromMillisecondsSinceEpoch(
    //       DateTime.now().millisecondsSinceEpoch + 1000 * 60 * 60 * 24);

    //   for (ChannelProgramItem item in data!.programItem) {
    //     DateTime dateTime =
    //         DateTime.fromMillisecondsSinceEpoch(item.dateStamp.toInt());
    //     if (DateUtil.isSameDay(dateTime, now)) {
    //       todayData.add(item);
    //     } else if (DateUtil.isSameDay(dateTime, tomorrow)) {
    //       tomorrowData.add(item);
    //     }

    //     if (item.status == ProgramStatus.PROCESS_ING) {
    //       isProgress = true;
    //     }
    //   }

    //   totalNumber = result.data!.hasMinSubscribeNumber()
    //       ? result.data!.minSubscribeNumber
    //       : 40;

    //   notifyListeners();
    // }
  }

  // /// 开活动上报
  // reportActivityStart(int rid, String activityName, int num) {
  //   Reporter.track(TrackEvent.activityStart, {
  //     "rid": rid,
  //     "activity_name": activityName,
  //     "num": num,
  //   });
  // }

  /// 预约活动上报
  reportActivityBook(int rid, String activityName, int num) {
    // Reporter.track(TrackEvent.activityBook, {
    //   "rid": rid,
    //   "activity_name": activityName,
    //   "num": num,
    // });
  }
}
